<?php
namespace app\work\validate;
use think\Validate;

/**
 * 工作记录日记账信息验证器
 * Created by PhpStorm.
 * User: tyll
 * Date: 2019/10/31
 * Time: 16:03
 */
class WorkRecordAccount extends Validate{

    protected $rule = [
        'now_date'          => 'require|date|checkDate',
        'receipt_number'    => 'require',
        'type'              => 'require',
        'abstract'          => 'require',
        'contract_number'   => 'require',
        'income_and_expend' => 'require',
        'money'             => 'require|float|regex:/^\d+(\.\d{0,2})?$/|egt:0'
    ];

    protected $message = [
        'now_date.require'          => '记账日期必须填写',
        'now_date.date'             => '记账日期填写错误',
        'now_date.checkDate'        => '记账日期必须小于当前日期',
        'receipt_number.require'    => '收据编号必须填写',
        'type.require'              => '类型必须填写',
        'abstract.require'          => '摘要必须填写',
        'contract_number.require'   => '合同编号必须填写',
        'income_and_expend.require' => '收支必须填写',
        'money.require'             => '金额必须填写',
        'money.float'               => '金额填写错误',
        'money.regex'               => '金额只能两位小数',
        'money.egt'                 => '金额填写错误'
    ];

    protected function checkDate($value){
        $now_date = date('Y-m-d');
        return $now_date < $value ? false : true;
    }

    protected $scene = [
        'add'  => ['now_date','receipt_number','type','abstract','income_and_expend','money'],
        'edit' => ['now_date','receipt_number','type','abstract','income_and_expend','money']
    ];
}